import ezdxf
from ezdxf.addons import odafc
from pathlib import Path
import numpy as np
from collections import defaultdict
import logging

logging.basicConfig(level=logging.INFO,filename='./retrieved_texts_from_dwgs.txt')


def retrieve_texts_from_dwgs(dwg):
  odafc.win_exec_path = r'C:\Program Files\ODA\ODAFileConverter 25.2.0\ODAFileConverter.exe'
  doc = odafc.readfile(dwg)
  msp = doc.modelspace()
  for entity in msp:
    if entity.dxftype() == 'LINE':
        # 提取线段的起点坐标和终点坐标
        start_point = entity.dxf.start
        end_point = entity.dxf.end
        print("Start Point:", start_point)
        print("End Point:", end_point)

def main():
    dwgs_folder = r"C:\Users\38083\Desktop"
    p = Path(dwgs_folder)
    dwg_files = p.glob('*.dwg')
    for dwg in dwg_files:
        retrieve_texts_from_dwgs(dwg)


if __name__ == "__main__":
    main()


